/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyClass;

import java.util.Random;
import java.util.Vector;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author HuuTai_it
 */
public class Vortexs {
    
    private int[] turn = new int[16];
    private int[] appear = new int[16];
    private int[] disappear = new int[16];
    
    public Vector vVortex = new Vector();
    
    private long time = System.currentTimeMillis();
    
    public Vortexs (GameManagement gameMng, Image image)  throws Exception {
<<<<<<< .mine

=======
>>>>>>> .r42
             
        Random r = new Random();
        time = System.currentTimeMillis();
        for(int i = 0; i < 16;)
<<<<<<< .mine
            turn[i] = 16 - ++i;        
=======
        {
            turn[i] = 15 - i; 
            disappear[i] = 16 + i;
            appear[i] = 31 - i++;
        }
       
        gameMng.element[0][0] = 2;
        gameMng.element[0][9] = 2;
        gameMng.element[9][9] = 2;
        gameMng.element[9][0] = 2;

        Sprite s1 = new Sprite(image, 24, 24);
        s1.setPosition(0, 0);
        s1.setFrameSequence(turn);
        vVortex.addElement(s1);

        Sprite s2 = new Sprite(image, 24, 24);
        s2.setPosition(0, 9 * 24);
        s2.setFrameSequence(turn);
        vVortex.addElement(s2);

        Sprite s3 = new Sprite(image, 24, 24);
        s3.setPosition(9 * 24, 9 * 24);
        s3.setFrameSequence(turn);
        vVortex.addElement(s3);

        Sprite s4 = new Sprite(image, 24, 24);
        s4.setPosition(9 * 24, 0);
        s4.setFrameSequence(turn);
        vVortex.addElement(s4);     
>>>>>>> .r42
        
        int numVortex = 4 - gameMng.control.difficulties + 1;
        
        for(int i = 0; i < numVortex;) {
            
            int x = Math.abs(r.nextInt() % 10);
            int y = Math.abs(r.nextInt() % 10);
            
            if(gameMng.element[x][y] == 0) {
                
                gameMng.element[x][y] = 2;
                
                Sprite s = new Sprite(image, 24, 24);
                s.setPosition(x * 24, y * 24);
                s.setFrameSequence(turn);
                s.setVisible(true);
                vVortex.addElement(s);
                i++;
            }
        }  
    }
    
    public void turn(long currTime) {        
        
        if(currTime - time > 30)
        {
            for(int i = 0; i < vVortex.size(); i++)
                ((Sprite)vVortex.elementAt(i)).prevFrame();            
            

            time = currTime;
        }
    }
}